﻿
@{
    ViewBag.Title = "AddNews";
    Layout = "~/Areas/AdminInfo/Views/Shared/_LayoutPage1.cshtml";
}
<script src="~/Scripts/utf8-net/ueditor.config.js"></script>
<script src="~/Scripts/utf8-net/ueditor.all.min.js"></script>
<script src="~/Scripts/utf8-net/lang/zh-cn/zh-cn.js"></script>
@model Gtkj.CMS.Model.NewInfo
<div class="container-fluid larry-wrapper">
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12">
            <section class="panel panel-padding">
              
                <form id="form1" class="layui-form layui-form-pane" data-render="true">
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="Title" value="@(Model==null?"": Model.Title)" required jq-verify="required" jq-error="请输入标题" placeholder="请输入标题" autocomplete="off" class="layui-input ">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">来源</label>
                        <div class="layui-input-block">
                            <input type="text" name="Source" value="@(Model==null?"": Model.Source)" required jq-verify="required" jq-error="请输入来源" placeholder="请输入来源" autocomplete="off" class="layui-input ">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">简介</label>
                        <div class="layui-input-block">
                            <input type="text" name="ShortTitle" value="@(Model == null ? "" : Model.ShortTitle)" required jq-verify="required" jq-error="请输入简介" placeholder="请输入简介" autocomplete="off" class="layui-input ">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">上传图片</label>
                        <div class="layui-input-inline">
                            <input type="file" name="Logo" class="layui-upload-file">
                            <input type="hidden" name="Image" id="imgsrc" value="@(Model == null ? "" : Model.Image)">
                            <p id="img-error" class="error">
                                @{
                                    if (Model != null)
                                    {
                                        if (Model.Image != null || Model.Image != "")
                                        {
                                            <img src="@Model.Image" alt="..." class="img-thumbnail">
                                        }
                                    }
                                }
                            </p>

                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">分类</label>
                        <div class="layui-input-inline">
                            <select name="NewTypeID" id="NewTypeID" jq-verify="required" jq-error="请输入分类" lay-filter="verify">
                                <option value="">请选择</option>
                                @{
                                    foreach (Gtkj.CMS.Model.NewType item in ViewBag.NewType)
                                    {
                                        <option value="@item.ID">@item.TypeName</option>
                                    }
                                }
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item ">
                        <label class="layui-form-label">排名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="Sorting" onkeydown=" if (!(event.keyCode == 46) && !(event.keyCode == 8) && !(event.keyCode == 37) && !(event.keyCode == 39))
     if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)))
         event.returnValue = false;" required jq-verify="number" value="@(Model == null ? 0 : Model.Sorting == null ? 0 : Model.Sorting)" jq-error="排名必须为数字" placeholder="请输入排名" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item ">
                        <label class="layui-form-label">阅读量</label>
                        <div class="layui-input-inline">
                            <input type="text" onkeydown=" if (!(event.keyCode == 46) && !(event.keyCode == 8) && !(event.keyCode == 37) && !(event.keyCode == 39))
     if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)))
         event.returnValue = false;" name="Reading" required jq-verify="number" value="@(Model == null ? 0 : Model.Reading == null ? 0 : Model.Reading)" jq-error="阅读量必须为数字" placeholder="请输入阅读量" autocomplete="off" class="layui-input ">
                        </div>
                    </div>
                   
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否首页推荐</label>
                        <div class="layui-input-block">
                            <select name="IsTop" id="IsTop" lay-filter="verify">
                                <option value="">请选择</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item ">
                        <label class="layui-form-label">内容</label>
                        <div class="layui-input-block">
                            <script id="editor" type="text/plain" style="width:100%;height:500px;">
                                @(Model == null ? null : Html.Raw(Model.Conntenst))
                            </script>
                            @*<textarea class="layui-textarea layui-hide" name="content" lay-verify="content" id="LAY_demo_editor">@(Model == null ? null : Html.Raw(Model.Conntenst))</textarea>*@
                            @*<textarea name="content" id="conntent" style="display:none;">@(Model == null ? "": Model.Contentxt)</textarea>*@
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
                            @if (Model == null)
                            {
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            }
                        </div>
                    </div>
                    <input type="hidden" name="ID" value="@(Model==null?"":Model.NewId.ToString())" />
                </form>
            </section>
        </div>
    </div>
</div>

<script>
    var $;
    //var $Type = $("Type");
    layui.use(['form', 'upload', 'jqform'], function () {
        var editIndex;
        $ = layui.jquery,
            jqform=layui.jqform,
         form = layui.form(), layedit = layui.layedit;
        UE.getEditor('editor');
        $("#NewTypeID").val(@(Model ==null?"":Model.TypeID.ToString()));
        $("#IsTop").val(@(Model ==null?"":(bool)Model.IsTop?"1":"0"));
        form.render(); //这个很重要
        layui.upload({
            url: '/Upload/UploadPic' //上传接口file1
         , success: function (res) { //上传成功后的回调
             console.log(res);
             $('#img-error').html("");
             $('#imgsrc').val(res.data);
             $('#img-error').append('<img src="' + res.data + '" alt="..." class="img-thumbnail">');
         }
        });

        form.on('submit(sub)', function (data) {
            //layedit.getContent(index)
            data.field["content"] = UE.getEditor('editor').getContent();
            //$('#LAY_demo_editor').val(layedit.getContent(editIndex));
            $.post('/AdminInfo/AdminNews/AddNewsInfo', data.field, function (r) {
                if (r.status == 200) {
                    layer.msg(r.message, {
                        icon: 6,
                        time: 2000,
                    });
                } else {
                    layer.msg(r.message, { icon: 2 });
                }
            });
            return false;
        });
        //jqform.completed = function (ret, options, that) {
        //    if (ret.status == 200) {
        //        layer.msg(ret.message, {
        //            icon: 6,
        //            time:2000,
        //        })
        //        //window.parent.document.getElementById("yyy").style.display = "none";
        //    } else {
        //        layer.msg(ret.message);
        //    }
        //    //form.close(that);
        //}
    });
    @*$(function () {
        $('#Type').val(@(Model ==null?"":Model.Type.ToString()));
    })*@
</script>

